Skip to content

fix(fleet-proxy): broker singleton lock + broker.pid ownership (#9611) - #10056

Merged
dezren39 merged 1 commit into
mainfrom
queue/16540-9611-broker-singleton
Nov 15, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/16540-9611-broker-singleton

Conversation

@dezren39

@dezren39 dezren39 commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

For #9611 (task 16540) — acceptance 1, the fleet-proxy leg of the broker singleton.

Problem (from #9611): two broker implementations auto-start against the same broker.sock. The Python broker (~/tools/laptop-agent-broker.py) already holds an exclusive flock on broker.lock for its lifetime and writes broker.pid only when it owns the socket — but fleet proxy serve played by neither rule: it probe-connects, unlinks "stale" sockets, and binds, without participating in the lock, and it never writes broker.pid. Two starters can both pass the stale probe and race to bind (episode 1: Errno 98 churn), and a fleet-proxy takeover leaves broker.pid naming a dead Python process (episode 2 tail).

Change (pkgs/fleet/crates/fleet-proxy/src/serve.rs, +81):

  • acquire_singleton_lock(): opens broker.lock beside the socket and takes flock(LOCK_EX | LOCK_NB), mirroring the Python broker exactly (same file, same semantics — the lock releases automatically when the holder dies, so a crashed broker never wedges the path).
  • run_inner takes the lock before the probe/bind sequence and holds it for the process lifetime. If another implementation holds it, serve logs and exits 0 — convergence on the existing owner instead of competition.
  • After a successful bind, serve writes broker.pid with its own pid, so broker.pid names the socket owner whichever implementation owns it.
  • New unit test singleton_lock_is_exclusive_across_open_descriptions (flock is per open-file-description: second acquisition fails while held, succeeds after drop).

Verification: cargo test -p fleet-proxy --lib — 90/90 pass, including the new test (run on the laptop through the fleet build lock).

The Python-broker legs of #9611 (acceptance 2 bounded tunnel establishment + pooled-only retry, alongside the already-landed 1/3/4) land in the home-tools tree and are verified live separately; the evidence note on #9611 ties the pieces together. This PR does not close #9611 — the coordinated broker restart verification is recorded on the issue.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Acceptance 1, fleet-proxy leg: fleet proxy serve now takes the
same cross-implementation singleton the Python broker holds — an
exclusive flock on broker.lock beside the socket, for the whole
process lifetime — before probing or binding broker.sock. If
another implementation holds it, serve converges (exit 0 with a
log line) instead of racing the stale-socket probe (episode 1:
Errno 98 churn) or silently taking the socket over (episode 2
tail). After a successful bind it writes broker.pid with its own
pid, so broker.pid names the socket owner whichever
implementation owns it (previously only the Python broker wrote
it). Unit test: flock exclusivity across open descriptions.
cargo test -p fleet-proxy --lib: 90/90 pass.
@dezren39
dezren39 requested a review from a team as a code owner November 14, 2026 14:31
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-14T14:31:15.790125Z
We couldn’t complete this review. Comment @codex review to try again.
bf65cba PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 14 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b54b56d2-7d50-49f3-8757-517e6ef75c42
Commits

Reviewing files that changed from the base of the PR and between 3b4cb17 and bf65cba.

Files selected for processing: 1

  • pkgs/fleet/crates/fleet-proxy/src/serve.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@dezren39

Copy link
Copy Markdown
Member Author

Drill item D5 for issue #8580 (task 16834): this PR comment was posted while the github-ci Worker webhook for developing-today/code is deactivated (kill-the-Worker drill). After reactivation + backfill sweep, the mirror's PR row for this PR must show the increased comments count.

@dezren39

Copy link
Copy Markdown
Member Author
{
  "agent-note": "v1",
  "task_id": 17367,
  "queue": "repo-health-code-pilot",
  "worker": "repo-worker-code",
  "lane": "any-n",
  "transition": "picked_up",
  "at": "2026-11-15T16:22:40Z",
  "summary": "Claimed by openchamber-scheduled-lane (repo-worker-code/any-n). Revalidated PR: OPEN, MERGEABLE, mergeStateStatus=CLEAN, checks NEUTRAL (CodeRabbit), no pending/failing, not draft, no CHANGES_REQUESTED. Proceeding to merge if state remains unchanged at merge time.",
  "origin": "openchamber-scheduled-lane"
}

@dezren39 dezren39 added work/assigned Queue worker lifecycle state queue/claimed Queue worker lifecycle state status/in-progress Queue worker lifecycle state labels Nov 15, 2026
@dezren39
dezren39 merged commit 32dc1f9 into main Nov 15, 2026
1 check passed
@dezren39
dezren39 deleted the queue/16540-9611-broker-singleton branch November 15, 2026 16:22
@dezren39

Copy link
Copy Markdown
Member Author
{
  "agent-note": "v1",
  "task_id": 17367,
  "queue": "repo-health-code-pilot",
  "worker": "repo-worker-code",
  "lane": "any-n",
  "transition": "done",
  "at": "2026-11-15T16:23:05Z",
  "summary": "Rechecked immediately before merge: OPEN, MERGEABLE, CLEAN, checks NEUTRAL (CodeRabbit), no pending/failing. Merged PR #10056 via merge commit. Task completed fixed_merged.",
  "origin": "openchamber-scheduled-lane"
}

@dezren39 dezren39 removed status/in-progress Queue worker lifecycle state queue/claimed Queue worker lifecycle state work/assigned Queue worker lifecycle state labels Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

defect: laptop-agent broker — no singleton across two implementations + silent CONNECT-pool wedge (two fleet-blind episodes, 2026-11-13)

1 participant